package jsyf.oa.web.pm;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.DateUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.pm.ProjectTrackFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * @projectName: oa-java
 * @title: ProjectTrack
 * @package jsyf.oa.web.pm
 * @description: 项目跟踪
 * @author: wangmin
 * @date: 2018/10/15 10:27
 */
@Api(value = "项目跟踪接口", description = "项目跟踪接口")
@Controller
@RequestMapping("/projectTrack")
public class ProjectTrackController {
    @Resource
    private ProjectTrackFacade projectTrackFacade;

    @RequestMapping(value = "/getProjectTrackInfo.json", method = RequestMethod.POST)
    public void getProjectTrackInfo(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> projectList = projectTrackFacade.getProjectList(jsonData);
        JSONObject planList = projectTrackFacade.getPlanList(jsonData);
        JSONObject getTrackList = projectTrackFacade.getTrackList(jsonData);
        JSONObject monthList = projectTrackFacade.getMonthList(jsonData);
        JSONObject objResult = new JSONObject();
        objResult.put("monthList", monthList);
        objResult.put("planList", planList);
        objResult.put("trackList", getTrackList);
        objResult.put("projectList", projectList);
        objResult.put("today", DateUtils.parse(new Date(), "yyyy-M-d"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }

    @RequestMapping(value = "/getLevel1ProjectList.json", method = RequestMethod.POST)
    public void getLevel1ProjectList(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> projectList = projectTrackFacade.getLevel1ProjectList(jsonData);
        JSONObject objResult = new JSONObject();
        objResult.put("projectList", projectList);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }

    @RequestMapping(value = "/getLevel1Level2ProjectById.json", method = RequestMethod.POST)
    public void getLevel1Level2Level3ProjectById(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = projectTrackFacade.getLevel1Level2Level3ProjectById(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
    }

    @RequestMapping(value = "/getLevel2ByLevel1Id.json", method = RequestMethod.POST)
    public void getLevel2ByLevel1Id(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> projectList = projectTrackFacade.getLevel2ByLevel1Id(jsonData);
        JSONObject objResult = new JSONObject();
        objResult.put("projectList", projectList);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }

    @RequestMapping(value = "/batchAddPlan.json", method = RequestMethod.POST)
    public void batchAddPlan(HttpServletResponse response, @RequestBody String jsonData) {
        projectTrackFacade.batchAddPlan(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond());
    }

    @RequestMapping(value = "/getProjectTrackByIdAndTrackDate.json", method = RequestMethod.POST)
    public void getProjectTrackByIdAndTrackDate(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = projectTrackFacade.getProjectTrackByIdAndTrackDate(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
    }

    @RequestMapping(value = "/saveProjectTrack.json", method = RequestMethod.POST)
    public void saveProjectTrack(HttpServletResponse response, @RequestBody String jsonData) {
        Integer r = projectTrackFacade.saveProjectTrack(jsonData);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", r);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
    }

    @RequestMapping(value = "/saveProjectOnwTwoThree.json", method = RequestMethod.POST)
    public void saveProjectOnwTwoThree(HttpServletResponse response, @RequestBody String jsonData) {
        Integer r = projectTrackFacade.saveProjectOnwTwoThree(jsonData);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", r);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
    }

    @RequestMapping(value = "/saveProjectThree.json", method = RequestMethod.POST)
    public void saveProjectThree(HttpServletResponse response, @RequestBody String jsonData) {
        Integer r = projectTrackFacade.saveProjectThree(jsonData);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", r);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
    }

    @RequestMapping(value = "/getProjectTrack.json", method = RequestMethod.POST)
    public void getProjectTrack(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> listById = projectTrackFacade.getTrackListById(jsonData);
        List<JSONObject> projectPrincipalList = projectTrackFacade.getProjectPrincipalList(jsonData);
        JSONObject planDate = projectTrackFacade.getTrackInfoById(jsonData);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("trackList", listById);
        jsonObject.put("principalList", projectPrincipalList);
        jsonObject.put("planDate", planDate);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
    }

    @RequestMapping(value = "/setProjectFinish.json", method = RequestMethod.POST)
    public void setProjectFinish(HttpServletResponse response, @RequestBody String jsonData) {
        Integer r = projectTrackFacade.setProjectFinish(jsonData);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", r);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
    }

}
